<?php include('header.php');?>
<style type="text/css">

ul.showInColumn {
	display: block;
	float: left;
	list-style: none;
	padding: 0px;
	margin: auto;
	width: 100%;
	border: 0px dotted #333333; /* เทียบใกล้เคียงกับการกำหนด  ของ table  */
}

ul.showInColumn li {
	list-style: none;
	display: block;
	float: left;
	margin: 5px; /* เทียบใกล้เคียงกับการกำหนด  cellspacing"  ของ table  */
	margin-left: 3px;
	border: 1px solid #333333;
	padding: 10px; /* เทียบใกล้เคียงกับการกำหนด  cellpadding  ของ table  */
	/* เทียบใกล้เคียงกับการกำหนด border ใน td ของ table  */
	width: 170px; /*  กำหนดความกว้างของแต่ละคอลัมน์  */
	height: 70px;
	word-wrap: break-word;
	
}

li.nReservation {
	background-color: #99CC99;	
}

li.rReservation {
	background-color: #FFFF66;
}

li.rReservation1 {
	background-color: #FF9933;
}

li.rReservation2 {
	background-color: #FF0000;
}

li.overmouse{
	background-color: #1BE059;
	cursor:pointer;
}

.clr {
	clear: both;
	float: none;
	height: 0;
	line-height: 0; /* fix ie */
	font-size: 0; /* fix ie */
	display: block; /* กรณีเอาใส่กับ tag อื่นที่ไม่ใช่ div หรือ p */
}
</style>

<body>
<?php 
$id = $_GET['id'];
$date = $_GET['date'];

	$DateThai = ThaiDate(strtotime($date));
?>
<form name="frmMain"  id="frmMain" method="post" action="room_edit_date_save.php">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>แก้ไขห้องพัก <?php echo $DateThai;?></h1>
        <div class="buttons">
<a class="button" onclick="document.frmMain.submit();"><span>บันทึก</span></a> <a class="button" onclick="window.location='room_edit_detail.php?id=<?php echo $id;?>';"><span>ยกเลิก</span></a>
</div></div>
<div class="content" align="center">
<input type="hidden" name="rID" value="<?php echo $id."#".$date;?>"/>
<input type="hidden" name="action" value="<?php echo $_GET['action'];?>"/>
<ul class="showInColumn">
<?php 
	$rQuery = mysql_query("SELECT room_id,room_name FROM room ORDER BY room_name");
	while($rRow = mysql_fetch_array($rQuery)){
		$roomid = $rRow['room_id'];
		if($_GET['action']=='edit'){
			$sQuery = mysql_query("SELECT reservation_session.room_id as room_id,reservation_session.reservation_status as reservation_status,reservation_detail.reservation_detail_id as reservation_detail_id,reservation_detail.reservation_detail_fname as reservation_detail_fname,reservation_detail.reservation_detail_lname as reservation_detail_lname,reservation_detail.reservation_detail_phone as reservation_detail_phone FROM reservation_session,reservation_detail WHERE reservation_session.reservation_detail_id = reservation_detail.reservation_detail_id AND room_id = '".$rRow['room_id']."' AND reservation_checkin = '$date' ");
		}
		if($_GET['action']=='add'){
			$sQuery = mysql_query("SELECT reservation.room_id as room_id,reservation.reservation_status as reservation_status,reservation_detail.reservation_detail_id as reservation_detail_id,reservation_detail.reservation_detail_fname as reservation_detail_fname,reservation_detail.reservation_detail_lname as reservation_detail_lname,reservation_detail.reservation_detail_phone as reservation_detail_phone FROM reservation,reservation_detail WHERE reservation.reservation_detail_id = reservation_detail.reservation_detail_id AND room_id = '".$rRow['room_id']."' AND reservation_checkin = '$date' ");
		}
		$sRow = mysql_fetch_array($sQuery);
		if($sRow){
			if($sRow['reservation_detail_phone']!=""){
				$phone = "โทร.".$sRow['reservation_detail_phone'];
			}
			
			if($id==$sRow['reservation_detail_id']){
				$checked = "checked=\"checked\"";
				$sStatus = $sRow['reservation_status'];
				$sCheck = "<input type=\"checkbox\" ".$checked." name=\"rCheck[]\" id=\"rCheck_".$rRow['room_id']."\" value=\"$roomid#$sStatus\"/>";
			} else {
				$checked = "";
				$sCheck = "";
			}
		
			//กรณีจอง
			if($sRow['reservation_status']=='0'){
				$Room = "<font size=\"3\"><b>".$rRow['room_name']."</b></font><br>จอง".$sCheck."<br>".$sRow['reservation_detail_fname']." ".$sRow['reservation_detail_lname']."<br>".$phone;
				$rClass = "rReservation";
			}
			//กรณีจอง cf แล้ว
			if($sRow['reservation_status']=='1'){
				$Room = "<font size=\"3\"><b>".$rRow['room_name']."</b></font><br>จอง CF แล้ว".$sCheck."<br>".$sRow['reservation_detail_fname']." ".$sRow['reservation_detail_lname']."<br>".$phone;
				$rClass = "rReservation1";
			}
			//กรณี เข้าอยู่แล้ว
			if($sRow['reservation_status']=='2'){
				$Room = "<font size=\"3\"><b>".$rRow['room_name']."</b></font><br>ไม่ว่าง<br>".$sRow['reservation_detail_fname']." ".$sRow['reservation_detail_lname']."<br>".$phone;
				$rClass = "rReservation2";
			}
			
		} else {
			$Room = "<font size=\"3\"><b>".$rRow['room_name']."</b></font><br>ว่าง<input type=\"checkbox\" name=\"rCheck[]\" id=\"rCheck_".$rRow['room_id']."\" value=\"$roomid#0\"/>";
			$rClass = "nReservation";
		}
?>
	<li <?php if($rClass!='rReservation2'){?>OnMouseOver="this.className='overmouse'" onmouseout="this.className='<?php echo $rClass;?>'" onclick="rCheckBox('rCheck_<?php echo $rRow['room_id'];?>','lCheck_<?php echo $rRow['room_id'];?>','<?php echo $rClass;?>');" <?php } ?> class="<?php echo $rClass;?>"><?php echo $Room;?></li>
<?php
	}
?>
</ul>
<div class="clr"></div>
</div>
</div>
</form>
</body>
<?php include('footer.php');?>
